package com.xc.hotelmgr.webapi.modules.op.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xc.hotelmgr.webapi.common.utils.RedisUtils;
import com.xc.hotelmgr.webapi.modules.dt.dao.StoreDao;
import com.xc.hotelmgr.webapi.modules.dt.entity.StoreEntity;
import com.xc.hotelmgr.webapi.modules.dt.service.StoreService;
import com.xc.hotelmgr.webapi.modules.op.dao.DtUpHtlDao;
import com.xc.hotelmgr.webapi.modules.op.entity.DtUpHtlEntity;
import com.xc.hotelmgr.webapi.modules.op.entity.StoreDateDao;
import com.xc.hotelmgr.webapi.modules.op.service.DateServeice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class DateServiceImpl extends ServiceImpl<StoreDao, StoreEntity> implements DateServeice{

    @Autowired
    private RedisUtils redisUtils;

    /**
     * 添加redis过滤日期
     * @param params
     */
    @Override
    public void set(Map<String, Object> params) {
        String storeId = params.get("storeId").toString();
        StoreEntity storeEntity = baseMapper.selectById(storeId);
        String appKey = storeEntity.getAppkey();
        List<String> dateList = (List<String>) params.get("dateList");
        if(dateList == null || dateList.isEmpty()) {
            return;
        }
        StoreDateDao storeDateDao = new StoreDateDao();
        storeDateDao.setDateList(dateList);
        redisUtils.set(appKey, storeDateDao, -1);
    }

    /**
     * 获取redis日期
     * @param storeId
     * @return
     */
    @Override
    public String get(Long storeId) {
        StoreEntity storeEntity = baseMapper.selectById(storeId);
        String appKey = storeEntity.getAppkey();
        return redisUtils.get(appKey);
    }

    /**
     * 获取分销商下店铺列表
     * @param dtId
     * @return
     */
    @Override
    public List<StoreEntity> getStore(Integer dtId) {
        List<StoreEntity> list = baseMapper.getByDtId(dtId);
        return list;
    }

    @Override
    public void del(Map<String, Object> params) {
        String storeId = params.get("storeId").toString();
        StoreEntity storeEntity = baseMapper.selectById(storeId);
        String appKey = storeEntity.getAppkey();
        redisUtils.delete(appKey);
    }
}
